#include <iostream>
#include <string>
#include <fstream>

using namespace std;

int main(int argc, char **argv)
{
    string filepath;
    ofstream f;
    if (argc > 1)
    {
        filepath = argv[1];

    }
    if(filepath.length())
        f = ofstream(filepath);
    if (!f.is_open())
        cout << "warning : not output file or failed to open it : " << filepath << endl;

    while (!cin.eof())
    {
        string line;
        getline(cin, line);
        cout << line << endl;

        if (f.is_open())
        {
            f << line << endl;
        }
    }
}